<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="/static/backstage/H-ui/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="/static/backstage/H-ui/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="/static/backstage/H-ui/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <title>下拉菜单列表</title>
</head>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i>首页
    <span class="c-gray en">&gt;</span>菜单管理
    <span class="c-gray en">&gt;</span><a href="/backstage/menu/max/list">菜单列表</a>
    <span class="c-gray en">&gt;</span>${maxMenu.maxName}
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>
<div class="page-container">
    <input id="maxId" type="hidden" value="${maxMenu.maxId}">
    <div class="text-c">
        <input id="select-input" type="text" class="input-text" style="width:250px" placeholder="输入导航菜单名称">
        <button id="select-btn" type="submit" class="btn btn-success">
            <i class="Hui-iconfont">&#xe665;</i>搜索
        </button>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <input id="add-input" type="text" class="input-text" style="width:250px" placeholder="输入菜单名称">
            <a id="add-btn" class="btn btn-primary radius">
                <i class="Hui-iconfont">&#xe600;</i> 添加菜单
            </a>
        </span>
        <span class="r">共有数据：<strong>${minMenuList.size()}</strong> 条</span>
    </div>
    <table class="table table-border table-bordered table-bg">
        <thead>
        <tr>
            <th scope="col" colspan="9">菜单列表</th>
        </tr>
        <tr class="text-c">
            <th width="40">ID</th>
            <th width="150">下拉菜单名</th>
            <th width="100">操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${minMenuList}" var="minMenu">
            <tr class="text-c">
                <td>${minMenu.minId}</td>
                <td>${minMenu.minName}</td>

                <td class="td-manage">
                    <a title="编辑" class="ml-5 edit" style="text-decoration:none">
                        <i class="Hui-iconfont">&#xe6df;</i>
                    </a>
                    <a title="删除" class="ml-5 del" style="text-decoration:none">
                        <i class="Hui-iconfont">&#xe6e2;</i>
                    </a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>

<script src="/static/backstage/H-ui/lib/jquery/1.9.1/jquery.min.js"></script>
<script src="/static/backstage/H-ui/lib/layer/2.4/layer.js"></script>
<script src="/static/backstage/H-ui/static/h-ui.admin/js/H-ui.admin.js"></script>

<script>
    // 点击"添加"
    $("#add-btn").click(function () {
        let name = $("#add-input").val().trim();
        if (name == "") {
            layer.msg("名称不能为空", {icon: 2, time: 1000});
            return;
        }
        $.post("/backstage/menu/min/add",
            {
                minName: name,
                maxId: $("#maxId").val()
            },
            function (data) {
                if (data.code == "1") {
                    window.location.reload();
                    $("#add-input").val("");
                } else {
                    //提示信息
                    layer.msg(data.message, {icon: 2});
                }
            });
    });

    // 点击"删除"
    $("tbody").on("click", ".del", function () {
        let id = $(this).parents("tr").children()[0].innerText;
        layer.confirm('确认要删除吗？', function () {
            $.post("/backstage/menu/min/del", {id: id}, function (data) {
                if (data.code == "1") {
                    window.location.reload();
                } else {
                    //提示信息
                    layer.msg(data.message, {icon: 2});
                }
            });
        })
    });

    // 点击"修改"
    $("tbody").on("click", ".edit", function () {
        let id = $(this).parents("tr").children()[0].innerText;
        layer_show("修改下拉菜单", "/backstage/menu/min/edit/" + id);
    });

    // 点击"搜索"
    $("#select-btn").click(function () {
        let name = $("#select-input").val().trim();
        window.location.href = '/backstage/menu/min/list/' + $("#maxId").val() + '/?minName=' + name;
    })
</script>
</body>
</html>